<?php
// add the admin options page
add_action('admin_menu', 'add_setting_page');

function add_setting_page() {
    add_options_page('InnoFlex Option', 'InnoFlex Option', 'manage_options', 'innoflex', 'innoflex_options_page');
}

// display the admin options page
function innoflex_options_page() {
    ?>
    <div class="wrap">
        <div class="icon32" id="icon-options-general"><br></div>
        <h2>InnoFlex Tabs Option</h2>
        <form action="options.php" method="post">
            <?php settings_fields('social_setting_section'); ?>
    <?php do_settings_sections('innoflex') ?>  
    <?php submit_button(); ?> 
        </form>
    </div><?php
}

function innoflex_settings_api_init() {
    // Add "innoflex_setting_section" section to reading settings so we can add our
    add_settings_section('social_setting_section', 'Homapage Tab', '', 'innoflex');

    // Add "link_youtube" field in to "social_setting_section" section
    add_settings_field(
            'link_tab1', 'Tab No.1', 'link_tab1_callback', 'innoflex', 'social_setting_section'
    );

    // Add "link_youtube" field in to "social_setting_section" section
    add_settings_field(
            'link_tab2', 'Tab No.2', 'link_tab2_callback', 'innoflex', 'social_setting_section'
    );

    // Add "link_youtube" field in to "social_setting_section" section
    add_settings_field(
            'link_tab3', 'Tab No.3', 'link_tab3_callback', 'innoflex', 'social_setting_section'
    );

    add_settings_field(
            'link_tab4', 'Tab No.4', 'link_tab4_callback', 'innoflex', 'social_setting_section'
    );

    register_setting('social_setting_section', 'link_tab1');
    register_setting('social_setting_section', 'link_tab2');
    register_setting('social_setting_section', 'link_tab3');
    register_setting('social_setting_section', 'link_tab4');
}

add_action('admin_init', 'innoflex_settings_api_init');

// Callback function for "link_tab1" field
function link_tab1_callback() {
    $categories = get_categories();
    ?>

    <select name="link_tab1"> <?php
    foreach ($categories as $category) {
        $selected = ( $category->cat_ID == get_option('link_tab1') ) ? 'selected' : '';
        echo '<option value="' . $category->cat_ID . '" ' . $selected . '>' . $category->name . '</option>';
    }
    ?>	

    </select><?php
}

// Callback function for "link_tab2" field
function link_tab2_callback() {
    $categories = get_categories();
    ?>

    <select name="link_tab2"> <?php
        foreach ($categories as $category) {
            $selected = ( $category->cat_ID == get_option('link_tab2') ) ? 'selected' : '';
            echo '<option value="' . $category->cat_ID . '" ' . $selected . '>' . $category->name . '</option>';
        }
        ?>	

    </select><?php
}

// Callback function for "link_tab3" field
function link_tab3_callback() {
    $categories = get_categories();
    ?>

    <select name="link_tab3"> <?php
        foreach ($categories as $category) {
            $selected = ( $category->cat_ID == get_option('link_tab2') ) ? 'selected' : '';
            echo '<option value="' . $category->cat_ID . '" ' . $selected . '>' . $category->name . '</option>';
        }
        ?>	

    </select><?php
}

// Callback function for "link_tab3" field
function link_tab4_callback() {
    $categories = get_categories();
    ?>

    <select name="link_tab4"> <?php
        foreach ($categories as $category) {
            $selected = ( $category->cat_ID == get_option('link_tab4x') ) ? 'selected' : '';
            echo '<option value="' . $category->cat_ID . '" ' . $selected . '>' . $category->name . '</option>';
        }
        ?>	

    </select><?php
}
?>
